<!DOCTYPE html>
<!--
  Copyright 2017 Google Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
-->
<html>
  <head>
    <meta charset="utf-8">
    <title>Slider - Material Components Catalog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
    <link rel="stylesheet" href="/assets/slider.css">
    <script src="/ready.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <style>
      #hero-slider-wrapper {
        margin: 0 auto;
        width: 100%;
        max-width: 600px;
        /* Blended equivalent of rgba(0, 0, 0, .05); */
        --mdc-slider-bg-color-behind-component: #f2f2f2;
      }

      .custom-bg {
        background-color: #eee;
        --mdc-slider-bg-color-behind-component: #eee;
      }

      .slider-example {
        margin-bottom: 48px;
      }

      .demo-param-field-group + .demo-param-field-group {
        margin-top: 16px;
      }

      .demo-param-field {
        display: block;
      }

      .demo-param-input-label {
        display: inline-block;
        min-width: 2.5em;
      }

      .example-slider-wrapper {
        padding: 0 16px;
      }
    </style>
  </head>
  <body class="mdc-typography">
    <header class="mdc-toolbar mdc-toolbar--fixed">
      <div class="mdc-toolbar__row">
        <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <a href="/" class="catalog-back mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
          <span class="mdc-toolbar__title catalog-title">Slider</span>
        </section>
      </div>
    </header>
    <main>
      <div class="mdc-toolbar-fixed-adjust"></div>
      <section class="hero">
        <div id="hero-slider-wrapper">
          <div id="hero-slider" class="mdc-slider" tabindex="0"
               role="slider" aria-valuemin="0" aria-valuemax="50" aria-valuenow="20"
               aria-label="Select Value">
            <div class="mdc-slider__track-container">
              <div class="mdc-slider__track"></div>
            </div>
            <div class="mdc-slider__thumb-container">
              <svg class="mdc-slider__thumb" width="21" height="21">
                <circle cx="10.5" cy="10.5" r="7.875"></circle>
              </svg>
              <div class="mdc-slider__focus-ring"></div>
            </div>
          </div>
        </div>
      </section>

      <section id="slider-example" class="example">
        <h2>Continuous Slider</h2>
        <div class="slider-example">
          <div class="example-slider-wrapper">
            <div id="continuous-mdc-slider" class="mdc-slider" tabindex="0" role="slider"
                 aria-valuemin="0" aria-valuemax="50" aria-valuenow="20"
                 aria-label="Select Value">
              <div class="mdc-slider__track-container">
                <div class="mdc-slider__track"></div>
              </div>
              <div class="mdc-slider__thumb-container">
                <svg class="mdc-slider__thumb" width="21" height="21">
                  <circle cx="10.5" cy="10.5" r="7.875"></circle>
                </svg>
                <div class="mdc-slider__focus-ring"></div>
              </div>
            </div>
          </div>

          <p>
            Value from <code>MDCSlider:input</code> event: <span id="continuous-slider-value"></span>
            <br>
            Value from <code>MDCSlider:change</code> event: <span id="continuous-slider-committed-value"></span>
          </p>
        </div>


        <h2>Discrete Slider</h2>
        <div class="slider-example">
          <div class="example-slider-wrapper">
            <div id="discrete-mdc-slider" class="mdc-slider mdc-slider--discrete" tabindex="0" role="slider"
                 aria-valuemin="0" aria-valuemax="50" aria-valuenow="20"
                 aria-label="Select Value">
              <div class="mdc-slider__track-container">
                <div class="mdc-slider__track"></div>
              </div>
              <div class="mdc-slider__thumb-container">
                <div class="mdc-slider__pin">
                  <span class="mdc-slider__pin-value-marker">20</span>
                </div>
                <svg class="mdc-slider__thumb" width="21" height="21">
                  <circle cx="10.5" cy="10.5" r="7.875"></circle>
                </svg>
                <div class="mdc-slider__focus-ring"></div>
              </div>
            </div>
          </div>

          <p>
            Value from <code>MDCSlider:input</code> event: <span id="discrete-slider-value"></span>
            <br>
            Value from <code>MDCSlider:change</code> event: <span id="discrete-slider-committed-value"></span>
          </p>
        </div>

        <h2>Discrete Slider with Tick Marks</h2>
        <div class="slider-example">
          <div class="example-slider-wrapper">
            <div id="discrete-mdc-slider-w-marker" class="mdc-slider mdc-slider--discrete mdc-slider--display-markers" tabindex="0" role="slider"
                 aria-valuemin="0" aria-valuemax="50" aria-valuenow="20"
                 aria-label="Select Value">
              <div class="mdc-slider__track-container">
                <div class="mdc-slider__track"></div>
                <div class="mdc-slider__track-marker-container">
                </div>
              </div>
              <div class="mdc-slider__thumb-container">
                <div class="mdc-slider__pin">
                  <span class="mdc-slider__pin-value-marker">20</span>
                </div>
                <svg class="mdc-slider__thumb" width="21" height="21">
                  <circle cx="10.5" cy="10.5" r="7.875"></circle>
                </svg>
                <div class="mdc-slider__focus-ring"></div>
              </div>
            </div>
          </div>

          <p>
            Value from <code>MDCSlider:input</code> event: <span id="discrete-slider-w-marker-value"></span>
            <br>
            Value from <code>MDCSlider:change</code> event: <span id="discrete-slider-w-marker-committed-value"></span>
          </p>
        </div>

        <h2>Custom Colored Discrete Slider with Tick Marks</h2>
        <div class="slider-example">
          <div class="example-slider-wrapper">
            <div id="custom-discrete-mdc-slider-w-marker" class="mdc-slider mdc-slider--discrete mdc-slider--display-markers demo-slider--custom" tabindex="0" role="slider"
                 aria-valuemin="0" aria-valuemax="50" aria-valuenow="20"
                 aria-label="Select Value">
              <div class="mdc-slider__track-container">
                <div class="mdc-slider__track"></div>
                <div class="mdc-slider__track-marker-container">
                </div>
              </div>
              <div class="mdc-slider__thumb-container">
                <div class="mdc-slider__pin">
                  <span class="mdc-slider__pin-value-marker">20</span>
                </div>
                <svg class="mdc-slider__thumb" width="21" height="21">
                  <circle cx="10.5" cy="10.5" r="7.875"></circle>
                </svg>
                <div class="mdc-slider__focus-ring"></div>
              </div>
            </div>
          </div>

          <p>
            Value from <code>MDCSlider:input</code> event: <span id="custom-discrete-slider-w-marker-value"></span>
            <br>
            Value from <code>MDCSlider:change</code> event: <span id="custom-discrete-slider-w-marker-committed-value"></span>
          </p>
        </div>

        <div class="demo-param-field-group">
          <label class="demo-param-field">
            <span class="demo-param-input-label">Min:</span>
            <input name="min" type="number" min="-100" max="100" value="0">
          </label>
          <label class="demo-param-field">
            <span class="demo-param-input-label">Max:</span>
            <input name="max" type="number" min="-100" max="100" value="50">
          </label>
          <label class="demo-param-field">
            <span class="demo-param-input-label">Step:</span>
            <input name="step" type="number" min="0" max="100" value="0">
          </label>
        </div>
        <div class="demo-param-field-group">
          <label class="demo-param-field">
            <input type="checkbox" name="disabled">
            Disabled
          </label>
          <label class="demo-param-field">
            <input type="checkbox" name="use-custom-color">
            Use Custom BG Color
          </label>
          <label class="demo-param-field">
            <input type="checkbox" name="rtl">
            RTL
          </label>
        </div>
      </section>
    </main>

    <script src="/assets/material-components-web.js" async></script>
    <script>
      demoReady(function() {
        mdc.slider.MDCSlider.attachTo(document.getElementById('hero-slider'));

        var numberIsFinite = Number.isFinite || function(value) {
          return typeof value === 'number' && isFinite(value);
        };

        var demoRoot = document.getElementById('slider-example')
        var minInput = demoRoot.querySelector('[name="min"]');
        var maxInput = demoRoot.querySelector('[name="max"]');
        var step = demoRoot.querySelector('[name="step"]');
        var disabled = demoRoot.querySelector('[name="disabled"]');
        var useCustomColor = demoRoot.querySelector('[name="use-custom-color"]');
        var rtl = demoRoot.querySelector('[name="rtl"]');

        var continuousValue = demoRoot.querySelector('#continuous-slider-value');
        var continuousCommittedValue = demoRoot.querySelector('#continuous-slider-committed-value');
        var continuousSliderEl = demoRoot.querySelector('#continuous-mdc-slider');
        var continuousSlider = new mdc.slider.MDCSlider(continuousSliderEl);
        continuousSlider.listen('MDCSlider:input', function() {
          continuousValue.textContent = continuousSlider.value;
        });
        continuousSlider.listen('MDCSlider:change', function() {
          continuousCommittedValue.textContent = continuousSlider.value;
        });

        var discreteValue = demoRoot.querySelector('#discrete-slider-value');
        var discreteCommittedValue = demoRoot.querySelector('#discrete-slider-committed-value');
        var discreteSliderEl = demoRoot.querySelector('#discrete-mdc-slider');
        var discreteSlider = new mdc.slider.MDCSlider(discreteSliderEl);
        discreteSlider.listen('MDCSlider:input', function() {
          discreteValue.textContent = discreteSlider.value;
        });
        discreteSlider.listen('MDCSlider:change', function() {
          discreteCommittedValue.textContent = discreteSlider.value;
        });

        var discreteWMarkerValue = demoRoot.querySelector('#discrete-slider-w-marker-value');
        var discreteWMarkerCommittedValue = demoRoot.querySelector('#discrete-slider-w-marker-committed-value');
        var discreteWMarkerSliderEl = demoRoot.querySelector('#discrete-mdc-slider-w-marker');
        var discreteWMarkerSlider = new mdc.slider.MDCSlider(discreteWMarkerSliderEl);
        discreteWMarkerSlider.listen('MDCSlider:input', function() {
          discreteWMarkerValue.textContent = discreteWMarkerSlider.value;
        });
        discreteWMarkerSlider.listen('MDCSlider:change', function() {
          discreteWMarkerCommittedValue.textContent = discreteWMarkerSlider.value;
        });

        var customDiscreteWMarkerValue = demoRoot.querySelector('#custom-discrete-slider-w-marker-value');
        var customDiscreteWMarkerCommittedValue = demoRoot.querySelector('#custom-discrete-slider-w-marker-committed-value');
        var customDiscreteWMarkerSliderEl = demoRoot.querySelector('#custom-discrete-mdc-slider-w-marker');
        var customDiscreteWMarkerSlider = new mdc.slider.MDCSlider(customDiscreteWMarkerSliderEl);
        customDiscreteWMarkerSlider.listen('MDCSlider:input', function() {
          customDiscreteWMarkerValue.textContent = customDiscreteWMarkerSlider.value;
        });
        customDiscreteWMarkerSlider.listen('MDCSlider:change', function() {
          customDiscreteWMarkerCommittedValue.textContent = customDiscreteWMarkerSlider.value;
        });

        minInput.addEventListener('input', function() {
          var minValue = parseFloat(minInput.value);
          if (!numberIsFinite(minValue)) {
            return;
          }
          continuousSlider.min = minValue;
          discreteSlider.min = minValue;
          discreteWMarkerSlider.min = minValue;
          customDiscreteWMarkerSlider.min = minValue;
        });

        maxInput.addEventListener('input', function() {
          var maxValue = parseFloat(maxInput.value);
          if (!numberIsFinite(maxValue)) {
            return;
          }
          continuousSlider.max = maxValue;
          discreteSlider.max = maxValue;
          discreteWMarkerSlider.max = maxValue;
          customDiscreteWMarkerSlider.max = maxValue;
        });

        step.addEventListener('input', function() {
          var stepValue = parseFloat(step.value);
          if (!numberIsFinite(stepValue)) {
            return;
          }
          continuousSlider.step = stepValue;
          discreteSlider.step = stepValue;
          discreteWMarkerSlider.step = stepValue;
          customDiscreteWMarkerSlider.step = stepValue;
        });

        disabled.addEventListener('change', function() {
          continuousSlider.disabled = disabled.checked;
          discreteSlider.disabled = disabled.checked;
          discreteWMarkerSlider.disabled = disabled.checked;
          customDiscreteWMarkerSlider.disabled = disabled.checked;
        });

        useCustomColor.addEventListener('change', function() {
          [].forEach.call(demoRoot.querySelectorAll('.example-slider-wrapper'), function(example) {
            example.classList[ useCustomColor.checked ? 'add' : 'remove' ]('custom-bg');
          });
        });

        rtl.addEventListener('change', function() {
          [].forEach.call(demoRoot.querySelectorAll('.example-slider-wrapper'), function(example) {
            if (rtl.checked) {
              example.setAttribute('dir', 'rtl');
            } else {
              example.removeAttribute('dir');
            }
          });
          continuousSlider.layout();
          discreteSlider.layout();
          discreteWMarkerSlider.layout();
          customDiscreteWMarkerSlider.layout();
        });
      });
    </script>
  </body>
</html>
